package com.mumu.jetpackdemo.navi;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import com.mumu.jetpackdemo.R;

import androidx.navigation.NavController;
import androidx.navigation.Navigation;

/**
 * - @Description: DemoNavigation使用<br/>
 * - @Author: edie<br/>
 * - @Time: 2019/4/1 上午10:54
 */
public class DemoNavigationActivity extends AppCompatActivity implements View.OnClickListener {


    public static void startNavigation(Context context) {
        context.startActivity(new Intent(context, DemoNavigationActivity.class));
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo_navigation);
        initView();
    }

    private void initView() {
//        myNavHostFragment = (fragment) findViewById(R.id.my_nav_host_fragment);

        findViewById(R.id.button4).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button4:
//                Navigation.findNavController(v).navigate(R.id.action_blank1Fragment_to_blank2Fragment2);
                NavController navController = Navigation.findNavController(this, R.id.my_nav_host_fragment);
                navController.navigate(R.id.action_blank1Fragment_to_blank2Fragment2);
                break;
        }
    }

    @Override
    public boolean onSupportNavigateUp() {
        return Navigation.findNavController(this, R.id.my_nav_host_fragment).navigateUp();
    }
}
